<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>猜数字游戏</title>
    
</head>
<body>
    <script>
        // 生成0到20的随机数字
function getRandomNum() {
    return Math.floor(Math.random() * 21);
}

let targetNum = getRandomNum();
let guessCount = 0;

while (guessCount < 5) {
    let userGuess = prompt("请输入您要猜的数字");
    // 判断用户是否点击取消
    if (userGuess === null) {
        break;
    }
    userGuess = parseInt(userGuess);
    guessCount++;

    if (userGuess === targetNum) {
        alert("恭喜您猜对啦");
        break;
    } else if (userGuess < targetNum) {
        alert("您猜的数字小了");
    } else {
        alert("您猜的数字大了");
    }

    if (guessCount === 5) {
        alert("这都猜不到");
    }
}
    </script>
    
</body>
</html>